package com.pdg.android.splorr.data;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class RoomItem extends Item<Room>{

	private static final String KEY_PREFIX_FORMAT = "item_%d_";

	private static final boolean DEFAULT_HIDDEN = false;

	private static final String SUBKEY_HIDDEN = "hidden";
	
	private boolean hidden = DEFAULT_HIDDEN;
	
	public RoomItem(Room theData) {
		super(theData);
	}
	public RoomItem(Room theData,Item<?> theOther) {
		super(theData,theOther);
	}
	@Override
	protected String getSubKey(String theSubKey) {
		String theResult =  getKeyPrefix()+theSubKey;
		System.out.println(String.format("SPLORR: %s", theResult));
		return theResult;
	}
	private String getKeyPrefix() {
		return getData().getKeyPrefix()+String.format(KEY_PREFIX_FORMAT, getData().getItemId(this));
	}
	@Override
	public Context getContext() {
		return getData().getContext();
	}
	@Override
	protected void onLoad(SharedPreferences thePreferences) {
		super.onLoad(thePreferences);
		setHidden(thePreferences.getBoolean(getSubKey(SUBKEY_HIDDEN), DEFAULT_HIDDEN));
	}
	@Override
	protected void onCommit(Editor theEditor) {
		super.onCommit(theEditor);
		theEditor.putBoolean(getSubKey(SUBKEY_HIDDEN), isHidden());
	}
	public boolean isHidden() {
		return hidden;
	}
	public void setHidden(boolean hidden) {
		this.hidden = hidden;
	}

}
